<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
           position: absolute;
           left: 0;
        }
    </style>
</head>
<body style="width: auto;">
    <img src="狗头-原谅.png" alt="">
</body>
<script>
    var img = document.querySelector('img')
    setInterval(function(){
        if(img.offsetLeft >= 400) {
            img.style.left = img.offsetLeft - 5 + 'px'
        }else {
            img.style.left = img.offsetLeft + 5 + 'px'
        }
    },30)
</script>
</html>